<template>
  <!-- pages/pay/index.wxml -->
  <view class="recharge">
    <view class="recharge-box">
      <view class="title">
        <image class="line-img" src="/static/orderDetail/ic_qb.png"></image>
        选择充值金额：
      </view>

      <view class="input-box">
        <input
          class="input"
          type="digit"
          placeholder="请输入整数金额(单位元)"
          v-model="money"
        />
      </view>

      <view class="item-num">
        <view
          :class="money == 10 ? 'num1 checked' : 'num1'"
          data-amount="10"
          @click="choose"
          >10元</view
        >
        <view
          :class="money == 20 ? 'num checked' : 'num default'"
          data-amount="20"
          @click="choose"
          >20元</view
        >
        <view
          :class="money == 30 ? 'num checked' : 'num default'"
          data-amount="30"
          @click="choose"
          >30元</view
        >
      </view>

      <view class="item-num">
        <view
          :class="money == 50 ? ' num1 checked' : 'num1 default'"
          data-amount="50"
          @click="choose"
          >50元</view
        >
        <view
          :class="money == 100 ? ' num checked' : 'num default'"
          data-amount="100"
          @click="choose"
          >100元</view
        >
        <view
          :class="money == 200 ? ' num checked' : 'num default'"
          data-amount="200"
          @click="choose"
          >200元</view
        >
      </view>

      <view class="btn btn-primary btn-recharge" @click="clickRecharge"
        >余额充值</view
      >
    </view>
  </view>
</template>

<script>
// import toast from '@/pages/components/toast/toast';
const app = getApp();
let Store = app.globalData.Store;
let Sign = app.globalData.Sign;
let Api = app.globalData.Api;
export default {
  components: {
    // toast
  },
  data() {
    return {
      money: '',
      user_id: ''
    };
  },
  onLoad: function () { },
  onShow: function () { },
  onReady: function () { },
  methods: {
    //手动输入金额
    getMoney(e) {
      let amount = e.detail.value;
      // this.setData({
      this.money = amount
      // });
    },

    //点选按钮
    choose(e) {
      let data = e.currentTarget.dataset;
      // this.setData({
      this.money = data.amount
      // });
    },

    // 点击充值 下单
    clickRecharge() {
      let user_id = Store.getItem('user_id');
      console.log(user_id);
      if (this.checkMoney(this.money)) {
        uni.navigateTo({
          url: '../walletToPay/walletToPay?user_id=' + user_id + '&price=' + this.money
        });
      } else {
        //跳转前 判断金额的格式
        uni.showToast({
          title: '请选择金额或输入整数金额!',
          icon: 'none',
          duration: 1500
        });
      }
    },

    checkMoney: function (money) {
      if (money != '' && money != null) {
        var moneyString = money.toString();
        if (moneyString.indexOf('.') == -1 && moneyString.indexOf('。') == -1) {
          return true;
        } else {
          return false;
        }
      } else {
        return false;
      }
    }
  }
};
</script>
<style>
@import "./walletSelMoney.css";
</style>
